<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./libs/vue3.js"></script>
</head>

<body>
    <div id="app">
        <button @click="addItem">通过数组索引向数组中添加元素</button>
        <ul>
            <li v-for="item in list">{{item}}</li>
        </ul>
        <hr>
        <button @click="addAttr">向对象中动态增加属性</button>
        <ul>
            <li v-for="item in user">{{item}}</li>
        </ul>
    </div>
</body>
<script>
    const app = Vue.createApp({
        el: '#app',
        data() {
            return {
                list: ['苹果', '香蕉', '水蜜桃'],
                user: {
                    name: 'jack'
                }
            }
        },
        methods: {
            addItem() {
                let index = this.list.length;
                this.list[index]='西瓜';
                console.log(this.list);
            },
            addAttr() {
                this.user.age=20;
                this.user.address='中国';
                console.log(this.user);
            }
        }
    });
    app.mount('#app');
</script>

</html>